<template lang="pug">
	.account-wrap
		.account-list
			field-item(text="姓名" :showArrow="false" :hint="list.name" v-if="list.realState==='1'")
			field-item(text="身份证号" :showArrow="false" :showBorder="false" :hint="list.idNumberText" v-if="list.realState==='1'")
			.field-wrap(v-else @click="authenticate")
				field-item(text="实名认证" :showArrow="true" hint="未认证" :color="hintColor" :showBorder="false")
		.account-list
			field-item(text="注册手机号" :showArrow="false" :hint="list.phoneText")
			.field-wrap(@click="updatePaswd")
				field-item(text="登录密码" :showArrow="true" :showBorder="false")
		.logout(@click="logout") 退出登录
</template>

<script>
import fieldItem from '@/components/field-item'
export default {
	name: 'account',
	data() {
		return {
			hintColor: '#3D8CFF',
			list: {
				name: '',
				phoneText: '',
				idNumberText: '',
				realState: '0'
			}
		}
	},
	created() {},
	onLoad() {
		Object.assign(this.$data, this.$options.data())
	},
	mounted() {
		this.getCardList()
	},
	methods: {
		getCardList() {
			this.api.tzApi
				.getCardList({
					mainHealthId: this.wx.getStorageSync('userInfo').memberNum
				})
				.then(data => {
					if (data.responseFlag === '1') {
						let list =
							data.data.find(item => item.familyRelation === '本人') || {}
						list.idNumberText = this.tools.hideNum(list.idNumber, 4, 4)
						list.phoneText = this.tools.hideNum(list.phone, 3, 4)
						this.list = list
					}
				})
				.catch(() => {})
		},
		authenticate() {
			this.wx.setStorage({
				key: 'familyRole',
				data: {
					name: this.list.name,
					idNumber: this.list.idNumber,
					familyRelation: '本人'
				}
			})
			this.$router.push({
				path: '/views/healthCard/insertId',
				query: {
					isReadFamily: '1',
					authentication: '1'
				}
			})
		},

		updatePaswd() {
			this.$router.push({
				path: '/views/login/updatePaswd'
			})
		},

		logout() {
			let that = this
			this.showModal({
				title: '提示',
				content: '确定退出登录吗？',
				confirmText: '确定',
				success: () => {
					that.wx.removeStorage({
						key: 'userInfo',
						success(res) {
							that.$router.push({
								path: '/views/login/login'
							})
						}
					})
				}
			})
		}
	},
	components: {
		fieldItem
	}
}
</script>

<style lang="stylus">
	.account-wrap
		.account-list
			margin-top mainMargin
		.logout
			margin-top 80px
			font-size 30px
			line-height 42px
			font-weight 400
			height 100px
			display flex
			align-items center
			justify-content center
			background-color white
</style>
